package com.bufbomb.datastore;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class FlashInfo {
	private String name;
	private String description;
	private int count;
	private long id;
	@SuppressWarnings("unchecked")
	public FlashInfo(long id) throws Exception{
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			Query query = pm.newQuery(FlashItem.class);
			query.setFilter("id==targetId");
			query.declareParameters("String targetId");
			List<FlashItem> records = (List<FlashItem>) query.execute(id); 
			if (records.isEmpty()) {
				throw new Exception("Empty record.");
			}
			else
			{
				FlashItem item = records.get(0);
				this.name = item.getName();
				this.description = item.getDescription();
				this.count = item.getCount();
				this.id = id;
			}
		}
		finally
		{
			pm.close();
		}
	}
	
	public String getName(){
		return this.name;
	}
	
	public String getDescription()
	{
		return this.description;
	}
	
	public int getCount(){
		return this.count;
	}
	
	
	public long getId(){
		return this.id;
	}
}
